import React, { PureComponent,Fragment } from "react";
import { connect } from "dva";
import moment from "moment";
import { Row, Col, Spin, Card, Button, Icon, message } from "antd";
import DescriptionList from '../../../components/DescriptionList';
import PtathCuring from '../../Path/Components/PtathCuring'
import styles from '../../Pbulic.less';

const { Description } = DescriptionList;

@connect(({ task, path, global,loading }) => ({
  pathcuring:path.pathcuring,
  dictionaries: global.dictionaries,
  detaildata:task.detaildata,
  loading:task.loading.detailinfo,
}))
export default class DetailInfo extends PureComponent {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const { match, dispatch} = this.props;
    const detailInfoId = match.params.id && match.params.id!='detail' ? match.params.id : 0;
    detailInfoId!==0 && dispatch({
      type: "task/fetch_task_info",
      payload: {
        taskId: detailInfoId
      }
    });
  }



  render() {
    const { match, detaildata, loading, dictionaries, pathcuring } = this.props;
    const detailInfoId = match.params.id;
    const planExecuteTime = dictionaries.planExecuteTime && dictionaries.planExecuteTime.length>1
      ? dictionaries.planExecuteTime.map(item=>item.label)
      :[];

    return (
      <Fragment>
        {loading && <div className={"globalSpin"}><Spin spinning={loading}  /></div>}
        {
          !loading && detaildata && detaildata.taskId &&
          <Row gutter={{ md: 8, lg: 24, xl: 48 }} className={styles.small_card}>
            <Col md={8} sm={24} >
              <Card title={"任务信息"}
                    bodyStyle={{padding:24}}
              >
                <DescriptionList col={1} size="large" style={{ marginBottom: 32 }}>
                  <Description term="任务编号">{detaildata.taskCode}</Description>
                  <Description term="任务名称">{detaildata.taskName}</Description>
                  <Description term="执行时间">{`${detaildata.beginTime && moment(detaildata.beginTime).format("YYYY-MM-DD")}至${detaildata.endTime && moment(detaildata.endTime).format("YYYY-MM-DD")}`}</Description>
                  {
                    detaildata.planId &&
                    <Fragment>
                      <Description term="计划编号">{detaildata.planCode}</Description>
                      <Description term="计划名称">{detaildata.planName}</Description>
                      <Description term="计划类型">{planExecuteTime[parseInt(detaildata.planType)-1]}</Description>
                    </Fragment>
                  }
                  <Description term="维保单位">{detaildata.maintenanceName}</Description>
                  <Description term="养护人">{detaildata.maintainManName}</Description>
                  <Description term="备注">{detaildata.remarks}</Description>
                  <Description term="编制人">{detaildata.creatorName}</Description>
                </DescriptionList>

              </Card>
            </Col>
            <Col md={16} sm={24} >
              <Card
                title={"任务路线"}
                bodyStyle={{padding:'1px 24px 24px 24px'}}
              >
                <PtathCuring
                  tableData={pathcuring}
                  dictionaries={dictionaries}
                  onlyview={true}
                />
              </Card>
            </Col>
          </Row>
        }
      </Fragment>
    );
  }
}
